local sk__bolve = fk.CreateSkill {

  name = "sk__bolve",

  tags = { Skill.Compulsory, },

}



sk__bolve:addEffect(fk.BeforeTurnStart, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__bolve.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("sk__renji")
    for _, kingdom in ipairs({"wei", "shu", "wu"}) do
      mark[kingdom] = mark[kingdom] or 1
    end
    local skills = {}
    for _, general in ipairs(room.general_pile) do
      local g = Fk.generals[general]
      if mark[g.kingdom] then
        skills[g.kingdom] = skills[g.kingdom] or {}
        table.insertTableIfNeed(skills[g.kingdom], g:getSkillNameList())
      end
    end
    math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
    local get = {}
    for kingdom, skill_list in pairs(skills) do
      skill_list = table.filter(skill_list, function(s)
        return not player:hasSkill(s, true)
      end)
      if #skill_list > 0 then
        table.insertTableIfNeed(get, table.random(skill_list, mark[kingdom]))
      end
    end
    room:setPlayerMark(player, sk__bolve.name, get)
    room:handleAddLoseSkills(player, get, nil, true, false)
  end,
})
sk__bolve:addEffect(fk.BeforeTurnStart, {
  can_refresh = function(self, event, target, player, data)
    return target == player and #player:getTableMark(sk__bolve.name) > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-"..table.concat(player:getTableMark(sk__bolve.name), "|-"), nil, true, false)
    room:setPlayerMark(player, sk__bolve.name, 0)
  end,
})

return sk__bolve